﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AssessmentList.aspx.cs" Inherits="House客户端.AssessmentList" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>显示估价列表页面</title>
    <link href="easyui/easyui/1.3.4/themes/default/easyui.css" rel="stylesheet" />
    <link href="easyui/easyui/1.3.4/themes/icon.css" rel="stylesheet" />
    <link href="easyui/easyui/1.3.4/demo/demo.css" rel="stylesheet" />
</head>
<body>
    <div>
        <a href="#" class="easyui-linkbutton" id="Assessment">评估</a>&nbsp;
        <select id="option" style="width: 100px;" class="easyui-combobox">
            <option value="请选择">请选择</option>
            <option value="The_Department">所属部门</option>
            <option value="ProjectNumber">项目号</option>
            <option value="Loan_Name">借款人</option>
            <option value="House_Located">房屋坐落</option>
        </select>
        <select id="optionchild" class="easyui-combobox" style="width: 100px;">
            <option value="请选择">请选择</option>
        </select>
        <a class="easyui-linkbutton" href="#" id="query">查询</a>
    </div>
    <div>
        <table id="list">
        </table>
    </div>
    <script src="easyui/easyui/1.3.4/jquery.min.js"></script>
    <script src="easyui/easyui/1.3.4/jquery.easyui.min.js"></script>
    <script src="jquery-easyui-1.5.2/Common.js"></script>
    <script type="text/javascript">
        ///绑定数据
        $(function () {
            $('#list').datagrid({
                singleSelect: true,
                columns: [[
                 { field: 'ck', checkbox: true, title: '操作', width: 100 },
                 { field: 'ProjectNumber', title: '项目号', width: 100 },
                 { field: 'The_Department', title: '所属部门', width: 100, },
                 { field: 'Survey', title: '勘察人', width: 100, },
                 { field: 'Survey_StartTime', title: '勘查开始时间', width: 100 },
                 { field: 'Survey_EndTime', title: '勘察结束时间', width: 100 },
                 { field: 'Basic_CreateTime', title: '登记日期', width: 100 },
                 { field: 'Basic_UnitPrice', title: '建议评估单价（元）', width: 100 },
                 {
                     field: 'Basic_State', title: '项目状态', width: 100,
                     formatter: function (value, row, index) {
                         return row.Basic_State == 1 ? "待约勘" : row.Basic_State == 2 ? "待评估" : row.Basic_State == 3 ? "已评估" : row.Basic_State == 4 ? "初审未通过" : row.Basic_State == 5 ? "初审通过" : row.Basic_State == 6 ? "终审未通过" : row.Basic_State == 7 ? "终审通过" : row.Basic_State == 8 ? "勘查中" : ""
                     }
                 },
                ]]
            });
            var option = $("#option").combobox('getValue');
            var optionchild = $("#optionchild").combobox('getValue');
            $.ajax({
                type: "get",
                url: WebApiURL + "api/Assessment/GetAssessmentList/?option=" + option + "&optionchild=" + optionchild,
                success: function (data) {
                    data = eval(data);
                    $("#list").datagrid("loadData", data);
                }
            });
        });
        $("#optionchild").combobox({
            editable: false,
        })
        //onSelect事件
        $("#option").combobox({
            editable: false,
            onSelect: function () {
                var option = $("#option").combobox('getValue');
                if (option == "The_Department") {
                    // 绑定部门表的信息
                    $.ajax({
                        type: "Get",
                        url: WebApiURL + "api/Department",
                        success: function (obj) {
                            obj = eval(obj);
                            $("#optionchild").combobox({
                                editable: false,
                                data: obj,
                                valueField: "ID",
                                textField: "Department_Name",
                            });
                        }
                    });
                }
                if (option == "ProjectNumber") {
                    // 查询所有项目号
                    $.ajax({
                        type: "Get",
                        url: WebApiURL + "api/Register/GetProjectNumber",
                        success: function (obj) {
                            obj = eval(obj);
                            $("#optionchild").combobox({
                                editable: false,
                                data: obj,
                                valueField: "ProjectNumber",
                                textField: "ProjectNumber",
                            });
                        }
                    });
                }
                if (option == "Loan_Name") {
                    // 借款人
                    $.ajax({
                        type: "Get",
                        url: WebApiURL + "api/Register/GetLoanName",
                        success: function (obj) {
                            obj = eval(obj);
                            $("#optionchild").combobox({
                                editable: false,
                                data: obj,
                                valueField: "Loan_Name",
                                textField: "Loan_Name",
                            });
                        }
                    });
                }
                if (option == "House_Located") {
                    // 房屋坐落
                    $.ajax({
                        type: "Get",
                        url: WebApiURL + "api/Register/GetHouseLocated",
                        success: function (obj) {
                            obj = eval(obj);
                            $("#optionchild").combobox({
                                editable: false,
                                data: obj,
                                valueField: "House_Located",
                                textField: "House_Located",
                            });
                        }
                    });
                }
            }
        })
        ///根据条件查询
        $("#query").bind("click", function () {
            var option = $("#option").combobox('getValue');
            var optionchild = $("#optionchild").combobox('getValue');
            $.ajax({
                type: "Get",
                url: WebApiURL + "api/Assessment/GetAssessmentList/?option=" + option + "&optionchild=" + optionchild,
                success: function (data) {
                    data = eval(data);
                    $('#list').datagrid('loadData', data);
                }
            });
        });
        ///评估
        $("#Assessment").bind("click", function () {
            var checkedItems = $('#list').datagrid('getChecked');
            var ProjectNumber = [];
            var state = [];
            $.each(checkedItems, function (index, item) {
                ProjectNumber.push(item.ProjectNumber);
                state.push(item.Basic_State);
            });
            if (ProjectNumber.length != 1) {
                $.messager.alert("温馨提示", "每次只能评估一个项目！");
                return;
            }
            if (state == 3) {
                $.messager.alert("温馨提示", "项目已经评估！");
                return;
            }
            location.href = 'Assessment.aspx?ProjectNumber=' + ProjectNumber;
        });
    </script>
</body>
</html>
